//
//  SASaleDocumentsHeaderView.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/5/11.
//

#import "SASaleDocumentsHeaderView.h"
#import "SASalesInvoiceDetailModel.h"
#import "SASalesOrderViewListModel.h"
#import "SAAllocateDetailModel.h"

@interface SASaleDocumentsHeaderView ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIImageView *imageV;

@end

@implementation SASaleDocumentsHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAProductListModel *)model {
    _model = model;
    self.titleLab.text = [NSString stringWithFormat:@"%@,%@",model.productCode,model.productName];
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"sale_bule_defaul"]];
}

-(void)setSaleModel:(SASalesOrderViewListModel *)saleModel {
    _saleModel = saleModel;
    self.titleLab.text = [NSString stringWithFormat:@"%@,%@",saleModel.productCode,saleModel.productName];
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:saleModel.img] placeholderImage:[UIImage imageNamed:@"sale_bule_defaul"]];
}

-(void)setReturnModel:(SAProductListModel *)returnModel {
    _returnModel = returnModel;
    self.titleLab.text = [NSString stringWithFormat:@"%@,%@",returnModel.productCode,returnModel.productName];
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:returnModel.img] placeholderImage:[UIImage imageNamed:@"sale_bule_defaul"]];
    if (returnModel.isReturn == NO) {
        _titleLab.textColor = kLightgGrayColor;
    }else {
        _titleLab.textColor = kBlackColor;
    }
}

-(void)setDetailModel:(dispatchDetailModel *)detailModel {
    _detailModel = detailModel;
    self.titleLab.text = [NSString stringWithFormat:@"%@,%@",detailModel.productCode,detailModel.productName];
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:detailModel.img] placeholderImage:[UIImage imageNamed:@"sale_bule_defaul"]];
}



-(void)clickedTab {
    !self.imageBlock ?: self.imageBlock();
}

-(void)initUI {
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.imageV];
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(65, 0, 300, 40)];
        _titleLab.textColor = kBlackColor;
        _titleLab.font = kFont(16);
    }
    return _titleLab;
}

-(UIImageView *)imageV {
    if (!_imageV) {
        _imageV = [[UIImageView alloc] initWithFrame:SARectMake(20, 3, 34, 34)];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickedTab)];
        [_imageV addGestureRecognizer:tap];
        _imageV.contentMode = UIViewContentModeScaleAspectFit;
        _imageV.userInteractionEnabled = YES;
    }
    return _imageV;
}


@end
